package com.lagou.homework123;

/**
 * 第一阶段模块二第三题作业：
 */
public class CommunicationServiceTest {


    public static void main(String[] args) {

        int monthTalkTime = 1000;
        int monthCellularData = 5120;
        int monthExpense = 199;

        System.out.println();
        SimCard simCard = new SimCard(SimCardType.Micro, "A001", "Lagou", "abc123", 1008611, monthTalkTime, monthCellularData);
        simCard.showSimCardInfo();


        //父类类型的引用指向子类类型的对象，形成了多态
        Plan plan1 = new TalkPlan(monthTalkTime, 50, monthExpense);
        Plan plan2 = new CellularPlan(monthCellularData, monthExpense);

        //对付父子类都有的静态方法来说，编译阶段和运行阶段都调用父类版本
        plan1.test();
        plan2.test();
        System.out.println();


        //对于父子类都有的非静态方法来说，编译阶段调用父类版本，运行阶段调用子类重写(Override)的版本（动态绑定）
        plan1.showPlanDetail();
        plan2.showPlanDetail();

        int talkTime = 23;
        int cellularData = 34;

        //当父类类型的引用指向子类类型的对象时，父类类型的引用不可以直接调用子类独有的方法,需要进行强制类型转换
        ((TalkPlan) plan1).call(talkTime, simCard);
        ((CellularPlan) plan2).surfInternet(cellularData, simCard);

        ConsumeInfo consumeInfo = new ConsumeInfo();
        consumeInfo.setTalkTime(talkTime);
        consumeInfo.setCellularData(cellularData);
        consumeInfo.setMonthExpense(8);
        consumeInfo.show();

        ((TalkPlan) plan1).call(talkTime+8, simCard);
        ((CellularPlan) plan2).surfInternet(cellularData+10, simCard);

        consumeInfo.setTalkTime(talkTime + 8);
        consumeInfo.setCellularData(cellularData + 10);
        consumeInfo.setMonthExpense(12);
        consumeInfo.show();


    }
}
